package linter.linterjava.controller.manage;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import linter.linterjava.POJO.DO.UserCard;
import linter.linterjava.POJO.DTO.UserDTO;
import linter.linterjava.custom.ResultVO;
import linter.linterjava.service.UserCardService;
import linter.linterjava.service.UserQueryService;
import linter.linterjava.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 北煜
 */
@Slf4j
@Api(tags = "基础管理模块")
@RestController
@RequestMapping("manage")
public class BaseManageController {

    @Resource
    UserService userService;
    @Resource
    UserCardService userCardService;
    private final UserQueryService userQueryService;
    @Autowired
    public BaseManageController(UserQueryService userQueryService) { this.userQueryService = userQueryService; }
    @GetMapping("/show/getUserByUsername/{username}")
    @ApiOperation("根据用户名查找用户")
    public ResultVO<UserDTO> getUserByUsername(@PathVariable String username) { return userQueryService.getUserByUsername(username); }


    @PostMapping("getManagerByUsername")
    @ApiOperation("根据用户名获取用户信息 -- 管理")
    public ResultVO<UserCard> getUserByUsername(@RequestBody UserDTO userDTO) {
        Long uuid = userService.getUserByUsername(userDTO.getUserName()).getId();
        return ResultVO.success(userCardService.getUserCardById(uuid));
    }

    @PostMapping("getManagerByUserId")
    @ApiOperation("根据用户id获取用户信息 -- 管理")
    public ResultVO<UserCard> getUserByUserId(@RequestBody UserDTO userDTO) {
        return ResultVO.success(userCardService.getUserCardById(userDTO.getId()));
    }

}
